package com.zut.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.zut.dao.MemberDao;
import com.zut.dao.OrderDao;
import com.zut.service.ReportService;
import com.zut.utils.DateUtils;
import org.springframework.beans.Mergeable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

/**
 * @author sq
 * @create 2021-07-20-10:42
 */
@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {

    @Autowired
    private MemberDao memberDao;
    @Autowired
    private OrderDao orderDao;

    //查询运营数据
    public Map<String, Object> getBusinessReportData() throws Exception {
        Map<String, Object> data = new HashMap<>();

        //获取当天的日期
        String today = DateUtils.parseDate2String(DateUtils.getToday());
        //获取本周一的日期
        String monday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //获取本月第一天的日期
        String firstDay = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());

        //报表日期
        data.put("reportDate", today);

        //本日新增会员人数
        Integer todayNewMember = memberDao.findMemberCountByDate(today);
        data.put("todayNewMember", todayNewMember);
        //本周新增会员人数
        Integer thisWeekNewMember = memberDao.findMemberCountAfterDate(monday);
        data.put("thisWeekNewMember", thisWeekNewMember);
        //本月新增会员人数
        Integer thisMonthNewMember = memberDao.findMemberCountAfterDate(firstDay);
        data.put("thisMonthNewMember", thisMonthNewMember);
        //会员总人数
        Integer totalMember = memberDao.findMemberTotalCount();
        data.put("totalMember", totalMember);

        //本日预约人数
        Integer todayOrderNumber = orderDao.findOrderCountByDate(today);
        data.put("todayOrderNumber", todayOrderNumber);
        //本周预约人数
        Integer thisWeekOrderNumber = orderDao.findOrderCountAfterDate(monday);
        data.put("thisWeekOrderNumber", thisWeekOrderNumber);
        //本月预约人数
        Integer thisMonthOrderNumber = orderDao.findOrderCountAfterDate(firstDay);
        data.put("thisMonthOrderNumber", thisMonthOrderNumber);

        //本日到诊人数
        Integer todayVisitsNumber = orderDao.findVisitsCountByDate(today);
        data.put("todayVisitsNumber", todayVisitsNumber);
        //本周到诊人数
        Integer thisWeekVisitsNumber = orderDao.findVisitsCountAfterDate(monday);
        data.put("thisWeekVisitsNumber", thisWeekVisitsNumber);
        //本月到诊人数
        Integer thisMonthVisitsNumber = orderDao.findVisitsCountAfterDate(firstDay);
        data.put("thisMonthVisitsNumber", thisMonthVisitsNumber);

        //热门套餐（取前4）
        List<Map> hotSetmeal = orderDao.findHotSetmeal();
        data.put("hotSetmeal", hotSetmeal);

        return data;
    }
}
